<template>
   <div  class="app-container"  >
         <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch">
            <el-form-item label="" prop="code">
               <el-input
                  v-model="queryParams.code"
                  placeholder="请输入合同编号"
                  clearable
                  style="width: 200px"
                  @keyup.enter="handleQuery"
               />
            </el-form-item>
            <el-form-item>
               <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
               <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
         </el-form>
   
         <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
               <el-button
                  type="primary"
                  plain
                  icon="Plus"
                  @click="handleAdd"
               >新增</el-button>
            </el-col>
            <right-toolbar :columns="columns" v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
         </el-row>
         <div class="data-tag"><span class="dit">数据列表 </span> 说明：可依据实际情况加入审批流程</div>
         <el-table
            v-loading="loading"
            :data="templateList"
            border 
         >
            <el-table-column prop="code" align="center" label="合同模板编号" :show-overflow-tooltip="true" width="160" v-if="columns[0].visible"></el-table-column>
            <el-table-column prop="name" label="合同模板名称" align="center" :show-overflow-tooltip="true" v-if="columns[1].visible"/>
            <el-table-column prop="type_name" align="center" label="合同类别" v-if="columns[2].visible"></el-table-column>
            <el-table-column prop="status" align="center" label="合同状态" :show-overflow-tooltip="true" v-if="columns[3].visible">
               <template #default="scope">
                 <div v-if="scope.row.status=='1'">是</div>
                 <div v-else-if="scope.row.status=='2'">否</div>
                 <div v-else>{{scope.row.status}}</div>
               </template>
            </el-table-column>
            <el-table-column prop="update_time" align="center" label="更新时间" :show-overflow-tooltip="true" v-if="columns[4].visible"></el-table-column>
   
            <el-table-column label="操作" align="center" width="210" class-name="small-padding fixed-width">
               <template #default="scope">
                  <el-button link type="primary"  @click="handleLoad(scope.row)" >下载</el-button>
                  <el-button  link type="primary" @click="handlePreview(scope.row)" >预览</el-button>
               </template>
            </el-table-column>
         </el-table>
         <pagination
         v-show="total > 0"
         :total="total"
         v-model:page="queryParams.page_size"
         v-model:limit="queryParams.page_count"
         @pagination="getList"
       />
      </div>
</template>

<script setup name="Template">
import {listTemplate } from "@/api/product/template";
const { proxy } = getCurrentInstance();
import {loanTypes} from '@/utils/dict'
const router = useRouter()
const templateList = ref([]);
const loading = ref(false);
const showSearch = ref(true);
const total = ref(0);//总条数
// 列显隐信息
const columns = ref([
  { key: 0, label: `合同模板编号`, visible: true },
  { key: 1, label: `合同模板名称`, visible: true },
  { key: 2, label: `合同类别`, visible: true },
  { key: 3, label: `合同状态`, visible: true },
  { key: 4, label: `更新时间`, visible: true },
]);
const data = reactive({
  queryParams: {
   page_size: 1,
   page_count: 10,
   code: undefined
  }
});

const { queryParams } = toRefs(data);
/** 查询菜单列表 */
function getList() {
  loading.value = true;
  listTemplate(queryParams.value).then(response => {
   loading.value = false;
   if(response.data.total_page > 0){
      templateList.value = response.data.list.map(item=>{
         item['type_name'] = loanTypes(item.type);
         return item;
      })
   }else{
      templateList.value = []
   }
   total.value = response.data.total_page;
  });
}
/** 搜索按钮操作 */
function handleQuery() {
   queryParams.value.page_size = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}
/** 新增按钮操作 */
function handleAdd() {
   router.push('addTemplate')
}
/**预览*/
function handlePreview(row){

}
/** 下载按钮操作 */
async function handleLoad(row) {
  
}

getList();
</script>
<style>
.data-tag{
margin-top: 30px;
padding-left:20px;
line-height: 52px;
font-size: 14px;
color: red;
background-color: rgba(243, 243, 243, 1);

}
.dit{
   color: black;
   font-weight: 800;
}
</style>
